﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;

namespace Drive.LiveExcelHost
{
    /// <summary>
    /// 在线用户数
    /// </summary>
    public class RedisAgentStatus
    {
        const string key = "status_agents";
        private static ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(RedisConf.connectionString);
        public static void SetStatusOnline(long agentId, bool bit)
        {
            redis.GetDatabase(1).StringSetBitAsync(key, agentId, bit);
        }

        public static bool GetIsStatusOnline(long agentId)
        {
            return redis.GetDatabase(1).StringGetBit(key, agentId);
        }

        public static long GetNumberOfStatusOnline()
        {
            return ConnectionMultiplexer.Connect(RedisConf.connectionString).GetDatabase(1).StringBitCount(key);
        }

        public static void Reset()
        {
            redis.GetDatabase(1).KeyDelete(key);
        }
    }
}
